package study.thread.lock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

//不公平重入锁
public class ReentrantLockUnfairBeanchmarkDemo implements Counter {
	//volatile变量
	private volatile long count = 0;
	private Lock lock;

	public ReentrantLockUnfairBeanchmarkDemo() {
		// 使用非公平锁，true就是公平锁 
		lock = new ReentrantLock(false);
	}

	public long getValue() {
		return count;
	}

	public void increment() {
		lock.lock();
		try {
			count++;
		} finally {
			lock.unlock();
		}
	}
}
